using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;


public class PlayClickAudio : MonoBehaviour
{
    public string m_AudioName;
    void Awake()
    {
        InitButton();
        InitToggle();
    }

    void InitButton()
    {
        Button btn = GetComponent<Button>();
        if (btn == null) return;
        btn.onClick.AddListener(() =>
        {
            if (AudioManager.Instance != null)
            {
                // Debug.LogFormat(gameObject.name);
                AudioManager.Instance.PlayAudioSource(m_AudioName);
            }
        });
    }

    void InitToggle()
    {
        Toggle toggle = GetComponent<Toggle>();
        if (toggle == null) return;
        toggle.onValueChanged.AddListener((value) =>
        {
            if (value && AudioManager.Instance != null)
            {
                // Debug.LogFormat(gameObject, gameObject.name);
                AudioManager.Instance.PlayAudioSource(m_AudioName);
            }
        });
    }
}
